Skip to content

b.number: the slider's editable readout without the track (#328, PR 3; based on #407) - #414

Merged
samitbasu merged 9 commits into
mainfrom
number-328
Nov 20, 2026
Merged

samitbasu merged 9 commits into
mainfrom
number-328

Conversation

@samitbasu

Copy link
Copy Markdown
Owner

Part of #328: PR 3 of 3, b.number. Based on #407 (which is based on #403): this PR targets #407's branch and moves to main as the stack merges.

One implementation, as the user decided on #328

API (rustdoc TODO(prose) where new)

impl Builder {
    pub fn number<K: Key>(&mut self, key: K, value: f64, range: impl Into<ValueRange>) -> NumberChain;
}
impl NumberChain {
    pub fn format(self, format: impl Fn(f64) -> String + 'static) -> Self;
    pub fn editable(self, parse: impl Fn(&str) -> Option<f64> + 'static) -> Self;
    pub fn step(self, step: Step) -> Self;
    pub fn named(self, name: impl Into<String>) -> Self;
    pub fn classes(self, classes: Tw) -> Self;   // merged over its own
    pub fn tooltip(self, text: impl Into<WidgetText>) -> Self;
    pub fn enablement(self, enablement: impl Into<Enablement>) -> Self;
    pub fn size(self, size: Size) -> Self;
    pub fn on_edit(self, then: impl Fn(&mut A, Edit) + 'static) -> Self;
    pub fn on_change(self, set: impl Fn(&mut A, f64) + 'static);
    pub fn add(self);                            // shows the value only, even after `.editable`
}

Behaviour changes

None to the slider: its 69 tests, the #403 and #407 tests included, pass unchanged.

Tests (tests/it/number_readout.rs, through the real draw path)

  • it shows the value as formatted, in the text colour around it;
  • Enter commits a typed value clamped and snapped, inside one edit ([Began, Ended]);
  • Escape reverts and closes the field;
  • it is a button "Edit Gain" that opens a field, which takes focus;
  • one added with .add() (even after .editable) only shows its value: no button, and a click opens nothing;
  • a disabled one doesn't open and reports no edit.

Mutations, each caught:

  • the number painted in the slider's readout colour;
  • add() keeping the parse;
  • a disabled one opening;
  • the slider's readout left unpainted.

To try (UI change: the user tries it before approval)

cargo xtask example slider_header. It gains two rows:

Click either readout to type in it. Enter or clicking away commits; Escape reverts.

Goldens

None changed: cargo xtask snapshots --update wrote nothing. The example has no golden.

Prose for you

TODO(prose) on:

  • NumberChain;
  • Builder::number;
  • NumberChain::format, editable, step and size.

git diff origin/typed-range-328 HEAD --stat (this PR alone)

 examples/slider_header.rs  |  23 ++-
 src/owned/mod.rs           |   2 +
 src/owned/readout.rs       | 382 +++++++++++++++++++++++++++++++++++++++++++++
 src/owned/slider.rs        | 161 +++----------------
 tests/it/main.rs           |   1 +
 tests/it/number_readout.rs | 123 +++++++++++++++
 6 files changed, 548 insertions(+), 144 deletions(-)

cargo xtask ci exits 0 on 21fa92c (on #407's 6833d6c).

🤖 Generated with Claude Code

https://claude.ai/code/session_01PWiKKf74MNWrhkW1CvKVUP

samitbasu and others added 3 commits November 18, 2026 20:41
One implementation for both, as the user decided on #328:

- owned/readout.rs: `Readout`, the readout a slider's header shows, moved
  out of the slider: its text, a button that opens it when it is
  editable, and the field it opens into (with #403's Session). The
  slider's header is its label plus a Readout, in the slider's muted
  readout colours.
- `Builder::number(key, value, range)` -> `NumberChain`: format,
  editable, step, named, classes (merged), tooltip, enablement, size,
  on_edit, then on_change, or add for one that only shows the value. It
  takes the text colour around it (the user's pick), and its range is
  the one a typed value reaches.
- examples/slider_header gains a Gain slider whose readout types past
  its track (#407) and a Trim number, for the trial.

Based on #407.

Part of #328.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKf74MNWrhkW1CvKVUP
# Conflicts:
#	src/owned/slider.rs
samitbasu and others added 6 commits November 19, 2026 12:47
# Conflicts:
#	tests/it/main.rs
#414 moved the readout, and the slider's focus import with it, to
readout.rs; #395 added focus_on_open and focus_now to the slider, which
use it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKf74MNWrhkW1CvKVUP
@samitbasu

Copy link
Copy Markdown
Owner Author

Approved by the user after the number-field trial (2026-11-19). GitHub's required checks pass on the branch merged with current main. Merging.

@samitbasu
samitbasu merged commit dff55f4 into main Nov 20, 2026
4 checks passed
samitbasu added a commit that referenced this pull request Nov 20, 2026
b.number: refused, when and when_some through the shared Gate (#328; based on #414)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant